<!DOCTYPE html>
<html>
<head>
    <title>多文件批量上传</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="../../js/jQuery/jquery-1.8.3.min.js"></script>
    <script src="../../js/jQuery/jquery.form.js"></script>
    <style type="text/css">
        .upload-default {
            border: 1px dashed red;
        }

        .upload-default.upload_drag_hover {
            border: 1px dashed green;
        }

        input {
            appearance: textfield;
            -moz-appearance: textfield;
            -webkit-appearance: textfield;
        }
        input[type="number"]::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }
        input[type="number"]::-webkit-outer-spin-button {
            -webkit-appearance: none;
        }
    </style>
</head>
<body>
<form name="importFile" id="importFile" method="post" enctype="multipart/form-data">
    <input title="点击选择多个文件" id="file" multiple="" accept="*/*" type="file" name="file" style="width: 300px;">
    <button onclick="importData()" style="padding: 5px 15px;background-color: #4D7607;border: 0px;color: #fff;">上传</button>

    <div id="fileList" style="width: 400px;height: 180px;padding: 3px;overflow: auto;" class="upload-default">
    </div>
</form>
</body>
</html>
<script type="text/javascript">
    var files = [];
    $(function () {
        $('#file').on('change', function () {
            $("#fileList").empty();
            files = this.files;
            for (var i = 0; i < this.files.length; i++) {
                $("#fileList").append('<div style="line-height: 22px;">' + (i + 1) + '，' + this.files[i].name + '</div>');
            }
        })
    });

    function importData() {
        if(files.length == 0) {
            top.isc.showMessage("请选择导入的文件", top.isc.OBMessageBar.TYPE_ERROR);
            return;
        }
        var options = {
            url: top.OB.Application.contextUrl+"./org.openbravo.client.kernel?_action=com.basis.handler.FileBatchUploadHandler",
            type: 'POST',
            dataType:'json',
            data:{},
            async: false,
            success: function(data){
                if(data.result){
                    top.OB.MyActiveViewRefresh();
                    top.isc.showMessage(data.msg, top.isc.OBMessageBar.TYPE_SUCCESS);
                    top.OB.Layout.ClassicOBCompatibility.Popup.close("_file_upload_Btn_001");
                }else{
                    top.isc.showMessage(data.msg, top.isc.OBMessageBar.TYPE_ERROR);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                top.isc.showMessage("上传失败", top.isc.OBMessageBar.TYPE_ERROR);
            }
        };
        $("#importFile").ajaxSubmit(options);
    }
</script>